package net.zm123.async;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import net.zm123.sync.RpcSyncClient;

import java.util.concurrent.CountDownLatch;

public class RpcAsyncClientApp {
    public static void main(String[] args) {
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9998)
                .usePlaintext()  // 这里是为了简化示例，生产环境中应该使用TLS
                .build();

        // 创建 CountDownLatch，等待异步调用完成
        CountDownLatch latch = new CountDownLatch(1);

        RpcAsyncClient client = new RpcAsyncClient(latch, channel);
        client.testActionMethod();

        try {
            latch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        channel.shutdown();//关闭
    }
}
